﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SistemaAcademicoBLL.Util;
using System.Web.Security;
using SistemaAcademicoBLL;

namespace SistemaAcademico.Pages
{
    public partial class LoginSAcademico : System.Web.UI.Page
    {
        #region FIELDS
        ApplicationFacade facade = new ApplicationFacade();
        #endregion

        #region PAGE EVENTS
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #endregion

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            SistemaAcademicoBO.Entities.User user = facade.GetUserByUserLogin(Login1.UserName);
            if (user != null)
            {
                string password = Criptografia.Descriptografa(user.UserPassword);
                if ((Login1.UserName == user.UserLogin) && (Login1.Password == password))
                {
                    Session["userId"] = user.UserId;
                    e.Authenticated = true;
                    FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
                }
                else
                {
                    e.Authenticated = false;
                }
            }
            else
            {
                e.Authenticated = false;
            }
        }
    }
}